package com.simon.train.business.controller.admin;


import com.simon.train.business.dto.TrainStationQueryDto;
import com.simon.train.business.dto.TrainStationSaveDto;
import com.simon.train.business.service.TrainStationService;
import com.simon.train.business.vo.TrainStationQueryVO;
import com.simon.train.common.Result.Result;
import com.simon.train.common.vo.PageVO;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/trainStation")
public class TrainStationAdminController {

    @Resource
    private TrainStationService trainStationService;

    @PostMapping("/save")
    public Result<Object> SaveTrainStation(@Valid @RequestBody TrainStationSaveDto trainStationSaveDto){
        trainStationService.SaveTrainStation(trainStationSaveDto);
        return new Result<>();
    }

    @GetMapping("/queryList")
    public Result<PageVO<TrainStationQueryVO>> TrainStationQueryList(@Valid TrainStationQueryDto trainStationQueryDto){
         /**
         * businessId通过线程变量获取 从而不需要由前端传入 保证了效率和安全性
         */
        PageVO<TrainStationQueryVO> lists = trainStationService.QueryTrainStationList(trainStationQueryDto);
        return new Result<>(lists);
    }

    @DeleteMapping("/delete/{id}")
    public Result<Object> DeleteTrainStation(@PathVariable("id") Long id){
        trainStationService.deleteTrainStation(id);
        return new Result<>();
    }

}
